home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / amac44d.zip / SR.QM < prev    next >
Text File  |  1992-06-22  |  8KB  |  175 lines

  1. *                                 SR.QM
  2. *       Search/Replace From Command Line Using SR.BAT and SZR.BAT
  3. *                                 6/8/92
  4. *
  5. * ----------------------------------------------------------------------
  6. * @(0) Search/Replace From Command Line Using SR.BAT and SZR.BAT,
  7. *      Can Also Remove Search Text
  8. * ----------------------------------------------------------------------
  9. * This macro performs a search/replace of both text files and text
  10. * files within zip files.  It is the autoexecutable macro to perform a
  11. * search/replace from the command line only using two batch files:
  12.  
  13. *     -   SR.BAT      Search/Replace Text Files
  14. *     -   SZR.BAT     Search/Replace Text Files Within Zip Files
  15. *                     Withoout Having to Manually Unzip and Rezip
  16.  
  17. * This version of this macro is a modification of previous versions of
  18. * SR.QM that now enables the user to also REMOVE search text by hitting
  19. * <enter> at the replacement text prompt, in addition to specified text
  20. * replacement.  Versions included with Amac43.zip and prior required
  21. * that some replacement text (Non-empty) be entered at the replacement
  22. * text prompt.
  23.  
  24. * FGREP.COM, INPUT.COM and QEdit v2.15 are required.  Changing c:\ to
  25. * you ram drive will increase speed.  Please refer to SR.BAT and SZR.BAT
  26. * for other details concerning entering optional parameters at the
  27. * command line or in response to input query prompts.
  28.  
  29. * SRCH.TST file is included to demonstrate use of this macro replacing
  30. * text in text files.
  31.  
  32. * As an example, at the command line enter the following commands:
  33.  
  34. *  1.   "sr"                <enter>
  35. *  2.   "sss" space "ttt"   <enter>   (answer SEARCH text prompt)
  36. *  3.   "SSS" space "TTT"   <enter>   (answer REPLACEMENT text prompt)
  37. *  4    "srch.tst"          <enter>   (answer FileList prompt)
  38.  
  39. * When completed, the following files remain loaded for viewing or
  40. * editing:
  41.  
  42. *    Window 1   c:\!  List of files found & search text by line
  43. *    Window 2   n+1   Files containing search text with replacements
  44. *                (n = # files containing search text)
  45.  
  46. * Temporary file names are:
  47.  
  48. * c:\$.ql  List of files found & search text (output from FGREP.COM)
  49. * c:\!     Same as c:\$.ql
  50. * c:\$     Output of Dos SET
  51.  
  52. @0      macrobegin
  53.         setsoundoff
  54.         altwordset                * For all file names
  55.         cursordown cursorup
  56.         jtrue START               * Test if any search text found
  57.     * --------------- Display "No found text" Message ---------------*
  58.     MESSAGE:
  59.         "No found text"                                                    *|
  60.         jump END                  * If not found, display this
  61.     * -------------------------- Load Files --------------------------*
  62.     START:
  63.         endfile
  64.     LOADAGAIN:
  65. *       unmarkblock               * Unmark last file name                  *|
  66.         setscreenon setscreenoff  * To reduce flashing
  67.         find
  68.             #42 "Fi" return
  69.             "B"  return           * Find file name
  70.         jfalse MESSAGE            * No find ?, show message, end
  71.         wordright wordright
  72.         markcolumn endline copy   * Copy file name to scrap
  73.         EditFile
  74.             CurrentFilename " "
  75.             Paste Return          * Load file
  76.         cursorup
  77.         jtrue LOADAGAIN           * Test if more filenames?
  78.     * ------------------ Get Search Text To Scratch ------------------*
  79.         editfile "c:\$" return    * Load set output file
  80.         find
  81.             "S~~" return
  82.             delline return        * Find S~~ in SET output
  83.         find
  84.             "=" return
  85.             delline return        * Move to =
  86.         cursorright markcharacter * Mark first character
  87.         endline                   * Move to end of text
  88.         storescrbuff "S~~" return * Store SEARCH text to scratch
  89.     * ----------------- Get Replace Text To Scratch -----------------*
  90.         unmarkblock begfile
  91.         find
  92.             "R~~" return
  93.             delline return        * Find R~~
  94.         jtrue FOUND               * If found, we specified replacement text*|
  95.         endline markcolumn        * If not, make empty block to clear buff *|
  96.         jump BLANK                                                         *|
  97.     FOUND:                                                                 *|
  98.         find
  99.             "=" return
  100.             delline return        * Move to =
  101.         cursorright markcharacter * Mark first character
  102.         endline                   * Move to end of text
  103.     BLANK:                                                                 *|
  104.         storescrbuff "R~~" return * Store REPLACE text to scratch
  105. *       killfile quit             * Kill/quit c:\$                         *|
  106.     * ---------------------- Do Search/Replace ----------------------*
  107. *       Editfile "NUL" Return     * Load NUL File                          *|
  108.         getscrbuff "S~~" return
  109.         cut                       * Cut search text from scratch
  110.         Find paste Return escape  * Initialize find prompt
  111.         getscrbuff "R~~" return
  112.         cut                       * Cut replace text from scratch
  113.         FindReplace
  114.             return paste return   * Begin replacement
  115.            "GIN"                  * Replace options
  116. *           pause                 ** Add this to pause for options
  117.             return                *   MUST include "GIN"
  118.         killfile quit             * Kill/quit c:\$                         *|
  119.     * ---------------- Load Files, Do Search/Replace ----------------*
  120.         Begfile Cursorright       * Put cursor in col 2 of c:\!            *|
  121. *       Begline Cursorright       * Put cursor in Col. 2 of NUL File       *|
  122.         setscreenon                                                        *|
  123.         LOOP:                     * Main test loop
  124.             Nextfile
  125.             Cursorleft Jfalse DOIT
  126.             Cursorleft Jfalse ENDLOOP
  127.         DOIT:                     * FindReplace Loop
  128.             BegFile               * Move up in case cursor is below find
  129.             Repeatfind            * Do the FindReplace
  130.             Jtrue SAVE            * If CHANGES are made -- SAVE the File
  131.             Quit                  * If NO CHANGES are made -- QUIT the file
  132.             Jump LOOP             * Return to the Main Loop
  133.         SAVE:                     * Routine to Save a File with Changes
  134.             Savefile              * Save the file
  135.             Jump LOOP             * Return to Main Loop
  136.         ENDLOOP:                  * Loop is DONE
  137. *       getscrbuff "R~~" return   * Get replacement text from scratch      *|
  138. *       cut                       * Cut replace text from scratch          *|
  139. *       Quit                      * Quit the NUL File                      *|
  140.         Find
  141.             paste return
  142.             delline return        * Initialize Find for f4
  143.         begfile
  144.  END:
  145. *       EditFile "c:\!" Return    * Load FGREP.COM output as first file    *|
  146.         defaultwordset
  147. *
  148. * 153 bytes Tue  10-02-1990  18:50:33
  149. * 223 bytes Thu  04-25-1991  11:57:13 added find initialize for search
  150. *                                     added "GIN" replace option
  151. *                                     added "No found text" message
  152. *                                     changed file "_" to "NUL", faster
  153. *                                     load FGREP.COM output as first file
  154. *                                                       after replacement
  155. * 231 bytes Tue  04-30-1991  22:12:13
  156. * 234 bytes Wed  04-15-1992  17:25:02 (TH @0, for QEdit v2.15)
  157. *                 (In Amac42e.zip)
  158. * 236 bytes Tue  05-12-1992  12:55:13 (TH @0, changed Find initialization)
  159. *                 (In Amac43.zip)
  160. * 213 bytes Mon  06-01-1992  17:07:07 (TH @0, will remove search text *|)
  161.  
  162.  
  163. * (f4)
  164. f4      repeatfind
  165.  
  166.  
  167. * (f5)
  168. f5      prevfile
  169.  
  170.  
  171. * (f6)
  172. f6      nextfile
  173.  
  174.  
  175.